//$Id: HibernateSessionFactory.java,v 1.1.2.2 2006/09/15 20:06:34 gilmar Exp $
package br.com.cefetrn.apoena.view.component;

import java.io.Serializable;

import org.hibernate.SessionFactory;
import org.hibernate.cfg.Configuration;
import org.hibernate.cfg.Environment;

import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;

import com.opensymphony.xwork.interceptor.component.Disposable;
import com.opensymphony.xwork.interceptor.component.Initializable;

/**
 * @author Gavin King
 * @author Gilmar
 */
public class HibernateSessionFactory
	implements Initializable, Disposable, Serializable {
	
	/**
	 * 
	 */
	private static final long serialVersionUID = 1L;

	private static final Log LOG = LogFactory.getLog(HibernateSession.class);
	
	private SessionFactory factory;
	
	public SessionFactory getSessionFactory() {
		return factory;
	}
	
	public void init() {
		try {
			factory = new Configuration().configure().buildSessionFactory();
		}
		catch (Exception e) {
			LOG.error("error configuring", e);
			throw new RuntimeException( e.getMessage() );
		}
	}
	
	public void dispose() {
		try {
			factory.close();
		}
		catch (Exception e) {
			LOG.error("error closing", e);
		}
	}
	
	public String getDialect() {
		return Environment.getProperties().getProperty(Environment.DIALECT);
	}

}
